import { _decorator, Component, instantiate, Node, Prefab, v3 } from 'cc';
import { ResourceUtil } from '../AshFramework/Utils/ResourceUtil';
import { YD } from './YD';
import { ZTool } from '../AshFramework/Utils/ZTool';
const { ccclass, property } = _decorator;

@ccclass('YDController')
export class YDController extends Component {

    @property({ type: Prefab })
    YDPrefab: Prefab = null;

    @property
    X: number = 0;

    @property
    MinY: number = 0;

    @property
    MaxY: number = 0;

    @property
    MinSpeed: number = 0;

    @property
    MaxSpeed: number = 0;

    protected onLoad(): void {
        this.createYD();
    }

    createYD() {
        this.schedule(() => {
            ResourceUtil.LoadPrefab("YD").then((prefab: Prefab) => {
                let node: Node = instantiate(prefab);
                node.parent = this.node;
                node.getComponent(YD).speed = ZTool.GetRandom(this.MinSpeed, this.MaxSpeed);
                let Y = ZTool.GetRandom(this.MinY, this.MaxY);
                node.setPosition(v3(this.X, Y));
            })
        }, 1)
    }

}


